package com.fc.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.web.bind.annotation.RequestMapping;
import com.fc.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.fc.entity.SysLog;
import com.fc.service.SysLogService;


import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 后台用户日志表 前端控制器
 * </p>
 *
 * @author zffc
 * @since 2023-07-17
 */
@Controller
@RequestMapping("/sysLog" )
    public class SysLogController {


        @Autowired
        private SysLogService sysLogService;

        @GetMapping("/toIndex" )
        public ModelAndView index(){
           ModelAndView mv=new ModelAndView();
           //因为配置了自带的视图解析器，所以默认访问template目录
           mv.setViewName("/sysLog/list" );
           return mv;
        }

        @GetMapping("/toAdd" )
        public ModelAndView toAdd(){
           ModelAndView mv=new ModelAndView();
           mv.setViewName("/sysLog/form" );
           return mv;
        }

        @GetMapping("/toEdit/{id}" )
        public ModelAndView toEdit(@PathVariable String id){//路径参数
            ModelAndView mv=new ModelAndView();
            SysLog sysLog = sysLogService.getById(id);
            mv.setViewName("/sysLog/form" );
            mv.addObject("sysLog" ,sysLog);
            return mv;
        }


         /**
         *
         * @param sysLog
         * @param pageNumber
         * @param pageSize
         * @return
         */
         @GetMapping("/list" )
         @ResponseBody
         public Result<?> list(SysLog  sysLog,
                @RequestParam(name = "pageNumber" , defaultValue = "1" ) Integer pageNumber,
                @RequestParam(name = "pageSize" , defaultValue = "10" ) Integer pageSize){
           Page<SysLog> page=new Page(pageNumber,pageSize);
           return Result.OK(sysLogService.page(page));
        }

         /**
         * 添加或修改方法
         * @param sysLog
         * @return
         */
         @PostMapping("/addOrEdit" )
         @ResponseBody
         public Result<?> addOrEdit(@RequestBody SysLog sysLog){
            sysLogService.saveOrUpdate(sysLog);
            return Result.OK("ok" );
         }

         /**
         * 删除
         * @param id
         * @return
         */
         @GetMapping("/delete/{id}" )
         @ResponseBody
         public Result<?> delete(@PathVariable String id){
            sysLogService.removeById(id);
            return Result.OK("ok" );
         }


}

